//
//  DYJiudianYuyueSubCell.swift
//  SheYangBigData
//
//  Created by 宋海胜 on 2021/1/11.
//  Copyright © 2021 叁拾叁. All rights reserved.
//



import UIKit
import YYText

class DYJiudianYuyueSubCell: SYBaseCell {

    
    
    let pic: UIImageView = {
        let v: UIImageView = UIImageView()
        v.layer.cornerRadius = 3
        return v
    }()
    
    let titleLb: UILabel = {
        let v:UILabel = UILabel()
        v.textColor = UIColor(hex: 0x1E1E1E)
        v.font = 15.autoFontSize()
        
        return v
    }()
    
    let contentLb: YYLabel = {
        let v:YYLabel = YYLabel()
        v.textColor = UIColor(hex: 0x666666)
        v.font = 13.autoBoldFontSize()
        
        return v
    }()
    
    let priceLb: YYLabel = {
        let v:YYLabel = YYLabel()
        v.font = 17.autoBoldFontSize()
        return v
    }()
    
    let yuyue: UIButton = {
        let v: UIButton  = UIButton()
        v.setTitle("预约", for: .normal)
        v.setTitleColor(UIColor.white, for: .normal)
        v.titleLabel?.font = 14.autoFontSize()
        v.layer.cornerRadius = 14
        v.backgroundColor = UIColor(hex: 0xFFA02A)
        v.isUserInteractionEnabled = false
        return v
    }()


    public func configureView(_ model: DYZSRoomListModel) {
        titleLb.text = model.name
        let showStr = "¥\(model.rates ?? "") 起"
        let attString = NSMutableAttributedString(string: showStr)
        attString.yy_setColor(UIColor(hex: 0xF55035), range: NSRange(location: 0, length: 1))
        attString.yy_setFont(10.autoFontSize(), range: NSRange(location: 0, length: 1))
        attString.yy_setColor(UIColor(hex: 0xF55035), range: NSRange(location: 1, length: showStr.count-2))
        attString.yy_setFont(14.autoFontSize(), range: NSRange(location: 1, length: showStr.count-2))
        attString.yy_setColor(UIColor(hex: 0xAFAFAF), range: NSRange(location: showStr.count-1, length: 1))
        attString.yy_setFont(10.autoFontSize(), range: NSRange(location: showStr.count-1, length: 1))
        priceLb.attributedText = attString
        
        if model.breakfast != 0 {
            let firstStr = "\(model.breakfast)份早餐"
            let xuzhiStr = "\(firstStr) \(model.label ?? "")"
            let xuzhiAttString = NSMutableAttributedString(string: xuzhiStr)
            xuzhiAttString.yy_setColor(UIColor(hex: 0x00C793), range: NSRange(location: 0, length: firstStr.count))
            xuzhiAttString.yy_setColor(UIColor(hex: 0x666666), range: NSRange(location: firstStr.count, length: xuzhiStr.count - firstStr.count))
            contentLb.attributedText = xuzhiAttString
        } else {
            contentLb.text = model.label ?? ""
        }
        pic.sy_setWithUrl(model.imgUrl)
    }
    
    override func initViews() {
        
        contentView.addSubview(priceLb)
        contentView.addSubview(yuyue)
        contentView.addSubview(pic)
        contentView.addSubview(titleLb)
        contentView.addSubview(contentLb)
        contentView.addSubview(lineView)
        
        yuyue.snp.makeConstraints { (make) in
            
            make.bottom.equalToSuperview().offset(autoWidth(-13.0))
            make.right.equalToSuperview().offset(autoWidth(-15.0))
            make.height.equalTo(28.0.autoWidth())
            make.width.equalTo(60.0.autoWidth())
        }
        pic.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(15.0.autoWidth())
            make.bottom.equalToSuperview().offset(-12.0.autoWidth())
            make.left.equalToSuperview().offset(autoWidth(15.0))
            make.width.height.equalTo(85.0.autoWidth())
        }
        titleLb.snp.makeConstraints { (make) in
            make.top.equalTo(pic.snp.top).offset(1.autoWidth())
            make.left.equalTo(pic.snp.right).offset(autoWidth(13.0))
            make.height.equalTo(15.5.autoWidth())
        }
        priceLb.snp.makeConstraints { (make) in
            make.bottom.equalTo(pic.snp.bottom).offset(-1.0.autoWidth())
            make.left.equalTo(titleLb)
            make.height.equalTo(13.5.autoWidth())
        }
        contentLb.snp.makeConstraints { (make) in
            make.top.equalTo(titleLb.snp.bottom).offset(9.5.autoWidth())
            make.left.equalTo(titleLb)
            make.height.equalTo(13.5.autoWidth())
        }
        lineView.snp.makeConstraints { (make) in
            make.bottom.equalTo(self.snp.bottom)
            make.left.right.equalTo(self)
            make.height.equalTo(0.5.autoWidth())
        }
    }
    
}

